/*** Replication do-file for:
Debus, Marc. 2024. "Negative Campaign Statements, Coalition Heterogeneity, and the Support for Government Parties." Electoral Studies. https://doi.org/10.1016/j.electstud.2023.102738.

Requires the data file "debus tuttnauer ES2024 data.dta"
finalised and run on Stata 18 on January 6, 2024 by Or Tuttnauer.
*/



* Load the dataset
use "debus tuttnauer ES2024 data.dta", clear

* Frequencies and descriptives
tab respondent_unique if n_cab>1 // number of unique respondents (coalitions only)
tab party_unique if n_cab>1 // number of unique cabinet parties (coalitions only)
sum  like_party sameside_focus range_coalition if n_cab>1 // descriptive statistics of main variables

* Correlation between range and campaign focus
pwcorr range_coalition sameside_focus if party_u==1 & n_cab>1, sig obs

* Figure 1
graph twoway lfitci sameside_focus range_coalition if party_u==1 & n_cab>1 || ///
scatter sameside_focus range_coalition if party_u==1 & n_cab>1, ///
legend(off) ytitle("Intra-coalition focus") xtitle("Ideological heterogeneity")

*Table 1
mixed like_party c.sameside_focus i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model1_main

mixed like_party c.sameside_focus range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model2_main

mixed like_party c.sameside_focus##c.range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model3_main
esttab model1_main model2_main model3_main, se r2 ar2 label replace noomit nobase nogaps 
		
* Figure 2
margins, dydx(range) at(sameside_focus = (0 (.05) 0.30))
marginsplot, name(all_voters1, replace) ytitle("") yline(0) addplot(hist sameside_focus if n_cab>1, yaxis(2) yscale(axis(2) alt) ///
	fintensity(inten30) color(%30) legend(off) ///
	ytitle("Density of nagative intra-coalition focus", axis(2) size(small))) title("Marginal effect of ideological range") ///
	 xtitle("Nagative intra-coalition focus")
margins, dydx(range) at(sameside_focus = (0 0.273))
di 7.63*.0666827 // one SD increase in range at the minimum level of conflict
di 7.63*-.1449424 // one SD increase in range at the maximum level of conflict
margins, dydx(sameside_focus) at(range = (0 (5) 30))
marginsplot, name(all_voters2, replace) ytitle("") yline(0) addplot(hist range_coalition if n_cab>1, yaxis(2) yscale(axis(2) alt) ///
	fintensity(inten30) color(%30) legend(off) ///
	ytitle("Density of ideological range", axis(2) size(small))) title("Marginal effect of campaign focus") ///
	 xtitle("Ideological range")

margins, dydx(sameside_focus) at(range = (0 27))
graph combine all_voters1 all_voters2, col(2)

* Figure 3
margins, at(range=(4 27) sameside_focus=(0 .18))
marginsplot, scheme(plotplain) legend(off) ///
	ytitle("Predicted sympathy score") xtitle("") ///
	plotopts(connect(none)) ///
	xlab(0 " " 4 "10th percentile range" 5 " " 27 "90th percentile range" 30 ///
		" ", notick) aspectratio(1) title("")



** Robustness tests **

// Table A1. Including SPGs
mixed like_party c.sameside_focus i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		 || country_year: || id: 
estimates store model1_spg

mixed like_party c.sameside_focus range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		 || country_year: || id: 
estimates store model2_spg

mixed like_party c.sameside_focus##c.range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		 || country_year: || id: 
estimates store model3_spg

esttab model1_spg model2_spg model3_spg, se aic bic label replace noomit nobase nogaps 

// Table A2. Using alternative ideological ranges

// Parlgov-based
mixed like_party c.sameside_focus parlgov_range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model2_parlgovrange

mixed like_party c.sameside_focus##c.parlgov_range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model3_parlgovrange

// Parlgov-based economy only
mixed like_party c.sameside_focus eco_range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model2_ecorange

mixed like_party c.sameside_focus##c.eco_range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model3_ecorange

// Pythagorean/Euclidean (two dimensional)
mixed like_party c.sameside_focus pyth i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model2_pythrange

mixed like_party c.sameside_focus##c.pyth i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model3_pythrange

// Categorical range
mixed like_party c.sameside_focus##range_cat i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 

esttab  model2_parlgovrange model3_parlgovrange ///
		model2_ecorange model3_ecorange ///
		model2_pythrange model3_pythrange ///
		, se aic bic label replace noomit nobase nogaps 

// Figure A1
margins, dydx(sameside_focus) at(range_cat = (1 (1) 4))
marginsplot, name(all_voters2, replace) yline(0) addplot(hist range_cat if n_cab>1 ///
	, yaxis(2) yscale(axis(2) alt) ///
	fintensity(inten30) color(%30) legend(off) ///
	ytitle("Density of ideological range", axis(2) size(small))) ///
	title("Marginal effect of campaign focus") ///
	xtitle("Ideological range")
graph export robustness_figure_a1.tif, replace

// Table A3. Alternative independent variables
// Only valence attacks
mixed like_party c.sameside_v_focus##c.range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model3_valence

// Only issue attacks
mixed like_party c.sameside_i_focus##c.range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model3_issue

esttab model3_valence model3_issue, se aic bic label replace noomit nobase nogaps 

// Table A4. Using vote recall
mixed like_party c.sameside_focus i.vote_recall pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model1_recall

mixed like_party c.sameside_focus range_coalition i.vote_recall pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model2_recall

mixed like_party c.sameside_focus##c.range_coalition i.vote_recall pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: 
estimates store model3_recall

esttab model1_recall model2_recall model3_recall, se aic bic label replace noomit nobase nogaps 

// Table A5. Using multilevel Tobit
metobit like_party c.sameside_focus i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: , ll(0) ul(10)
estimates store model1_tobit

metobit like_party c.sameside_focus range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: , ll(0) ul(10)
estimates store model2_tobit

metobit like_party c.sameside_focus##c.range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		if n_cab>1 || country_year: || id: , ll(0) ul(10)
estimates store model3_tobit

esttab model1_tobit model2_tobit model3_tobit, se aic bic label replace noomit nobase nogaps 

// Table A6. Fixed effects models
reg like_party c.sameside_focus i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		i.country_id i.year if n_cab>1 , vce(cluster id)
estimates store model1_fe

reg like_party c.sameside_focus range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		i.country_id i.year if n_cab>1  , vce(cluster id)
estimates store model2_fe

reg like_party c.sameside_focus##c.range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		i.country_id i.year if n_cab>1 , vce(cluster id)
estimates store model3_fe

esttab model1_fe model2_fe model3_fe, se r2 ar2 label replace noomit nobase nogaps 

// Table A7. Additional controls:
mixed like_party c.sameside_focus i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		unemployment inflation inter_conflict party_attach ///
		if n_cab>1 || country_year: || id: 
estimates store model1_controls

mixed like_party c.sameside_focus range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		unemployment inflation inter_conflict party_attach ///
		if n_cab>1 || country_year: || id: 
estimates store model2_controls

mixed like_party c.sameside_focus##c.range_coalition i.vote pm_party ///
		perceived_dist age gender i.education satisfaction  ///
		coalition_past pec gdpgrowth ///
		other_negative_focus received_negativity ///
		unemployment inflation inter_conflict party_attach ///
		if n_cab>1 || country_year: || id: 
estimates store model3_controls

esttab model1_controls model2_controls model3_controls, se aic bic label replace noomit nobase nogaps 

